package com.crv.ci.publish;

import com.crv.ci.model.*;
import com.crv.ci.service.IJobService;
import com.crv.ci.service.ITaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;

/**
 * Created by shurrik on 2016/1/7.
 */
@SuppressWarnings("unchecked")
@Service("JobManager")
public class JobManager {

    @Autowired
    private IJobService jobService;
    @Autowired
    private ITaskService taskService;
    @Autowired
    private TaskManager taskManager;



    public void create(Job job,List<JobBizType> jobBizTypes,List<JobBizUnit> jobBizUnits,TemplateShell templateShell)
    {
        //创建作业

        //两层嵌套
//        for agent
//            for agentNode
//        taskManager.create(job,agent,agentNode,templateShell);
    }

    public void run(Job job) throws Exception {

        List<Task> tasks  = taskService.findList("jobId",job.getId());
        for(Task task:tasks)
        {
            taskManager.run(job,task);
        }
        //修改作业状态

    }
}
